<template>
    <div class="login-wrap">
		<div class="ms-title" style="line-height: 120px;font-size: 30px;">myadmin管理系统</div>
        <div class="ms-login">
			<div class="ms-title" style="border-bottom: 1px solid #ccc;">登录</div>
            <el-form :model="param" :inline-message	='true' :rules="rules" ref="login" label-width="0px" class="ms-content">
                <el-form-item prop="wechatNumber">
                    <el-input v-model="param.wechatNumber" placeholder="登录账号">
                        <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="pass">
                    <el-input
                        type="password"
                        placeholder="登录密码"
                        v-model="param.pass"
                        @keyup.enter.native="submitForm()"
                    >
                        <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                    </el-input>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm()">登录</el-button>
                </div>
                <p class="login-tips">请输入账号与密码。
				<el-checkbox style="float: right;margin-right: 5px;color: white;" v-model="checked">记住密码</el-checkbox>
				</p>
            </el-form>
        </div>
    </div>
</template>

<script>
export default {
    data: function() {
        return {
            param: {
                wechatNumber: '',
                pass: '',
            },
			checked:false,
            rules: {
                wechatNumber: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                pass: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
        };
    },
    created(){
        if(this.user){
            this.param = this.user;
            this.checked = true;
        }else{
			this.param.wechatNumber = 'huacheng';
			this.param.pass = '159357';
		};
    },
    methods: {
        submitForm() {
            this.$refs.login.validate(valid => {
				console.log(valid,this.param)
                if (valid) {
                    this.sub();
                } else {
                    this.$message.error('请输入账号和密码');
                    //console.log('error submit!!');
                    return false;
                }
            });
        },
		sub(){
			// this.$router.push('/index');
			// return;
			this.$axios.post('/login',this.param).then((res)=>{
				var data = res.data;
				if(data.code == 200){
					$cookies.set('lifeData', JSON.stringify({}));//重新登录清除所有缓存
					this.vuex('vuex_user', data.lst[0],this.checked?-1:'');
					console.log(data.lst[0])
					this.vuex('user', this.param,this.checked?-1:'');
					this.$router.push('/index');
					this.$message.success('登录成功');
				}else{
					this.$message.error(data.info);
				}
			})
			// $.ajax({
			// 	url:this.url + '/loginuser_login',
			// 	data:this.param,
			// 	success:(data)=>{
   //                  console.log(data)
			// 		if(data.code == 200){
   //                      this.$message.success('登录成功');
                       
   //                     if(data.data.user.user.frole == 'admin'){
   //                         this.vuex('bgtype', '#0e1d3c');
   //                         this.vuex('texttype', '#bfcbd9');
   //                         this.vuex('activetexttype', '#20a0ff');
   //                     }else if(data.data.user.user.frole == 'onerole'){
   //                         this.vuex('bgtype', '#6e6dbc');
   //                         this.vuex('texttype', '#bfcbd9');
   //                         this.vuex('activetexttype', '#20a0ff');
   //                     }else if(data.data.user.user.frole == 'tworole'){
   //                         this.vuex('bgtype', '#fff');
   //                         this.vuex('texttype', '#bfcbd9');
   //                         this.vuex('activetexttype', '#20a0ff');
   //                     }
			// 			if(this.checked){
   //                          this.vuex('menu', data.data.menu,-1);
			// 				this.vuex('vuex_user', data.data.user,-1);
			// 				this.vuex('user',this.param ,-1);
			// 			}else{
   //                          this.vuex('menu', data.data.menu);
   //                          this.vuex('vuex_user', data.data.user);
   //                          this.vuex('user',false);
   //                      }
   //                      console.log(this.vuex_user)
			// 			$cookies.set('lifeData', JSON.stringify({}));//重新登录清除所有缓存
			// 			this.$router.push('/index');
			// 		}else{
			// 			this.$message.error(data.msgs);
			// 		}
			// 	},
			// 	error(){
			// 		this.$message.error('服务器错误！');
			// 	}
			// })
		}
    },
};
</script>

<style scoped>
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
}
.ms-title {
    width: 100%;
    line-height: 40px;
    text-align: center;
    color: #409EFF;
}
.ms-login {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>